package com.efast.dmom.aps.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.efast.dmom.aps.bean.ResultBean;
import com.efast.dmom.aps.bean.Station;
import com.efast.dmom.aps.entity.base.IModificationFlags;
import com.efast.dmom.aps.service.StationService;

@Controller
@RequestMapping(value = "/station")
public class StationsController {
	@Autowired
	private StationService stationservice;
	
	@RequestMapping(value = "/operateByStation")
	public @ResponseBody ResultBean operateByWorkshop(@RequestBody Station station) {
		ResultBean resultBean = new ResultBean(true, ' ');
		
		// Determine the new
		if (station.getInnerData().getModificationFlag() == IModificationFlags.NEW) {
			resultBean = stationservice.save(station);
			// Judge update
		} else if (station.getInnerData().getModificationFlag() == IModificationFlags.MODIFIED) {
			resultBean = stationservice.update(station);
			// Judge to delete
		} else if (station.getInnerData().getModificationFlag() == IModificationFlags.DELETED) {
			resultBean = stationservice.delete(station);
		}
		return resultBean;
	}

}
